﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using System.Xml;
using PloobsEngine.SceneControl;
using PloobsEngine.Modelo;

namespace PloobsEngine.Physics.XJigLib
{
    public class FollowerGhostObject : JigLibXObject
    {
         /// <summary>
        /// Serialization
        /// </summary>
     public FollowerGhostObject()
     {
     }

     public FollowerGhostObject(IObject obb)
     {
         this.ob = obb;
     }
         private IObject ob;
         private Vector3 displacement = Vector3.Zero;
         private Matrix rotation = Matrix.Identity;

     public override Vector3 Position
     {
         get
         {
             return ob.Position + displacement;
         }
         set
         {
             displacement = value;
         }
     }

     public override Microsoft.Xna.Framework.Matrix Rotation
     {
         get
         {
             return ob.PhysicObject.Rotation * rotation;
         }
         set
         {
             this.rotation = value;
         }
     }

     public override BoundingBox BoundingBox
     {
         get
         {
             return ob.PhysicObject.BoundingBox;
         }         
     }
     public override bool isMotionLess
     {
         get
         {
             return false;
         }
         set
         {
             throw new Exception("Eh sempre movel");
         }
     }
     public override float Mass
     {
         get
         {
             return -1;
         }
         set
         {
             throw new Exception("nao tem massa");
         }
     }
     public override void EnableBody()
     {
         
     }
     public override void DisableBody()
     {
         
     }
     public override void SetImobile()
     {
         
     }
     public override void OffsetModel(Vector3 PositionOffset, Matrix RotationOffset)
     {
         throw new Exception("nao skin associada");
     }
     public override Vector3 Velocity
     {
         get
         {
             return ob.PhysicObject.Velocity;
         }
         set
         {
             throw new Exception("Sempre imovel");
         }
     }
     public override Vector3 SetMass(float mass)
     {
         return Vector3.Zero;
     }        

        public override void DeSerialize(XmlNode node, EngineStuff engine, IModelo model, Vector3 position, Matrix rotation)
        {
            throw new Exception("NOT IMPLEMENTED YET");
            //this.Position = SerializerHelper.DeserializeVector3("Position", node);
            //this.Rotation = SerializerHelper.DeSerializeMatrix("Rotation", node);            
            //this.Scale = SerializerHelper.DeserializeVector3("Scale", node);
            //Vector3 bmax = SerializerHelper.DeserializeVector3("bbMIN", node);
            //Vector3 bmmin = SerializerHelper.DeserializeVector3("bbMAX", node);
            //bb = new BoundingBox(bmmin, bmax);
        }

        public override void Serialize(System.Xml.XmlTextWriter textWriter)
        {
            throw new Exception("NOT IMPLEMENTED YET");
            //SerializerHelper.SerializeVector3(Scale, "Scale", textWriter);
            //SerializerHelper.SerializeVector3(Position, "Position", textWriter);                        
            //SerializerHelper.SerializeMatrix(Rotation, "Rotation", textWriter);
            //SerializerHelper.SerializeVector3(bb.Max, "bbMAX", textWriter);
            //SerializerHelper.SerializeVector3(bb.Min, "bbMIN", textWriter);            
        }

        public override PhysicObjectTypes PhysicObjectTypes
        {
            get { return PhysicObjectTypes.GHOST; }
        }    
    
    }
}
